{*******************************************************}
{                                                       }
{       delphi message manipulation routines            }
{       windows 32bit interface unit                    }
{                                                       }
{       copyright (c) 1998-2009 maciej zagozda          }
{                                                       }
{*******************************************************}

unit srcMessageDialog;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, TB97Ctls, StdCtrls, Menus, ImgList, ShellApi,
  TFlatButtonUnit, StaticMemo, TFlatNormalButtonUnit, cxButtons;

type
  TfrmMessageDialog = class(TForm)
    ScrollBox1: TScrollBox;
    imgAsterisk: TImage;
    imgWarning: TImage;
    imgQuestion: TImage;
    imgStyle: TImage;
    popDefault: TPopupMenu;
    imlDefault: TImageList;
    popDefaultCopy: TMenuItem;
    popDefaultSend: TMenuItem;
    popDefault1: TMenuItem;
    popDefaultClose: TMenuItem;
    memMessage: TStaticMemo;
    lblTitle: TLabel;
    btn1: TcxButton;
    btn2: TcxButton;
    btn3: TcxButton;
    Image1: TImage;
    Image2: TImage;
    lblHeader: TLabel;
    btnDropdown: TToolbarButton97;
    btnClose: TToolbarButton97;
    imgInformation: TImage;
    procedure btnCloseClick(Sender: TObject);
    procedure popDefaultCopyClick(Sender: TObject);
    procedure popDefaultSendClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ButtonClick( Sender: TObject );
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    procedure WMNCHitTest(var M: TWMNCHitTest); message WM_NCHITTEST;
  end;

var
  frmMessageDialog: TfrmMessageDialog;

implementation

uses
  MessageRoutines;

{$R *.DFM}

procedure TfrmMessageDialog.WMNCHitTest(var M: TWMNCHitTest);
begin
  inherited;
  if  M.Result = htClient then M.Result := htCaption;
end;

//_____________________________________________________________________________

procedure TfrmMessageDialog.ButtonClick( Sender: TObject );
var
  strnButtonType: ShortString;
begin
  strnButtonType := TFlatNormalButton( Sender ).Caption;
  if AnsiCompareText( strnButtonType, MSGBOXDIALOG_OK ) = 0 then ModalResult := mrOK;
  if AnsiCompareText( strnButtonType, MSGBOXDIALOG_YES ) = 0 then ModalResult := mrYes;
  if AnsiCompareText( strnButtonType, MSGBOXDIALOG_NO ) = 0 then ModalResult := mrNo;
  if AnsiCompareText( strnButtonType, MSGBOXDIALOG_CANCEL ) = 0 then ModalResult := mrCancel;
end;

//_____________________________________________________________________________

procedure TfrmMessageDialog.btnCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmMessageDialog.popDefaultCopyClick(Sender: TObject);
begin
  with memMessage do
  begin
    SelectAll;
    CopyToClipboard;
  end;//with
end;

procedure TfrmMessageDialog.popDefaultSendClick(Sender: TObject);
begin
  ShellExecute( Handle, 'open', PChar( Format( 'mailto:intelitech@post.pl?subject=%s&body=%s', [lblTitle.Caption, memMessage.Text] )), nil, nil, SW_NORMAL );
end;

procedure TfrmMessageDialog.FormCreate(Sender: TObject);
begin
  HideCaret( memMessage.Handle );
  memMessage.Font.Name := 'Tahoma';
  memMessage.Font.Size := 10;
end;

procedure TfrmMessageDialog.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  {
  if ( Key = VK_RETURN ) then
  begin
    if AnsiCompareText( btn1.Caption, 'OK' ) = 0 then ButtonClick( btn1 );
    if AnsiCompareText( btn2.Caption, 'TAK' ) = 0 then ButtonClick( btn2 );
  end;//if

  if ( Key = VK_ESCAPE  ) then
  begin
    if AnsiCompareText( btn1.Caption, 'OK' ) = 0 then ButtonClick( btn1 );
    if AnsiCompareText( btn1.Caption, 'NIE' ) = 0 then ButtonClick( btn1 );
  end;//if
  }

end;

procedure TfrmMessageDialog.FormShow(Sender: TObject);
begin
  {
  Width := 363;
  Height := 264;
  }
end;

end.
